package com.activitycode.adapter;

import java.util.List;

import com.activitycode.datamodel.modelinfo.BookHotelInfo;
import com.activitycode.datamodel.modelinfo.BookHotelWaitInfo;
import com.activitycode.datamodel.modelinfo.SearchInfo;
import com.activitycode.tools.TimeTools;
import com.activitycode.util.CommConstant;
import com.helixinsoft.texi.driver.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


public class BookHotelAdapter extends BaseAdapter{
	
	public Context context;
	private List<BookHotelWaitInfo> infoList;
	public final String Tag ="HistoryAdapter";
	public BookHotelAdapter adapter;
	private ImageLoader imageLoader;
	private DisplayImageOptions options;
	public CallOnClickListener callOnClick;
	
	public BookHotelAdapter(Context ct,List<BookHotelWaitInfo> list){
		this.context = ct;
		this.infoList = list;
		
		adapter = this;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final int p = position;
		ViewHolder viewHolder = null;
		  
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_bookhotel, null);
            viewHolder.name = (TextView) convertView.findViewById(R.id.adapter_bookhotel_time); 
            viewHolder.add_time = (TextView) convertView.findViewById(R.id.adapter_bookhotel_addtime); 
            viewHolder.start = (TextView) convertView.findViewById(R.id.adapter_bookhotel_start); 
            viewHolder.end = (TextView) convertView.findViewById(R.id.adapter_bookhotel_end);
            viewHolder.catchOrder = (TextView) convertView.findViewById(R.id.adapter_bookhotel_capture);
            viewHolder.message = (TextView) convertView.findViewById(R.id.adapter_bookhotel_meeage);
            convertView.setTag(viewHolder);
        } else {
        	
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.message.setText(""+infoList.get(position).getOrder_msg());
        String date = TimeTools.getOrderTime(""+infoList.get(position).getOrder_sub_time());                
        viewHolder.name.setText(date);
        viewHolder.add_time.setText("");
        viewHolder.start.setText(""+infoList.get(position).getOrder_start());
        viewHolder.end.setText(""+infoList.get(position).getOrder_end());
        viewHolder.catchOrder.setBackground(context.getResources().getDrawable(R.drawable.style_login_submit));
        viewHolder.catchOrder.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				doCallOnClickListener(p);
			}
        	
        });

        
		return convertView;
	}
	public final static class ViewHolder {
        TextView name,start,end,catchOrder,add_time,message;
        
        
    }
	

	//
   	public interface CallOnClickListener {
   		  public void   onClick(int position);
   	}
   	public void doCallOnClickListener(int position) {
   	    callOnClick.onClick(position);
   	  }
   	 
      public void setCallOnClickListener(CallOnClickListener callback) {
          this.callOnClick = callback;
      }
	
	

}